package com.cratos.xxgram.platf.group;

import javax.persistence.*;
import com.cratos.xxgram.platf.base.BaseEntity;
import com.cratos.xxgram.platf.base.UserInfo;
import org.redkale.util.Comment;
import org.redkale.util.Reproduce;
import org.redkale.util.Utility;

/**
 *
 * @author SquRab
 */
@Table(comment = "群组信息")
public class GroupDetail extends BaseEntity {

    @Comment("普通群")
    public static final  short  GROUP_TYPE_NORMAL = 10;
    
    @Comment("匿名群")
    public static final  short  GROUP_TYPE_ANONYMOUS = 20;
    
    @Comment("对象拷贝")
    private static final Reproduce<GroupDetailHis, GroupDetail> copyer = Reproduce.create(GroupDetailHis.class, GroupDetail.class);
    
    @Comment("群名称最大长度")
    public static final int GROUPNAME_MAXLEN = 20; 
    
    @Id
    @Column(comment = "群组ID")
    private int groupid;

    @Column(length = 64, comment = "群组名称")
    private String groupname = "";

    @Column(comment = "创建人")
    private int createuserid;

    @Column(updatable = false, comment = "创建时间")
    private long createtime;

    @Column(comment = "群信息更新时间")
    private long infotime;
    
    @Column(comment = "当前人数")
    private int usernum;

    @Column(comment = "群公告")
    private String groupnotice = "";

    @Column(comment = "群头像")
    private String groupface = "";

    @Column(comment = "ecdh加密私钥")
    private String ecdhprivkey;
    
    @Column(comment = "ecdh加密公钥")
    private String ecdhpubkey;
    
    @Column(comment = "群类型 10 普通群 20 匿名群")
    private short grouptype;
    
    @Column(comment = "系统配置 第1位表示 全员禁言  第2位表示 群消息回执 ")
    private long syssetting;
       
    @Comment("创建用户")
    @Transient
    private  UserInfo creator;
    @Transient
    private  short status;



	@Comment("聊天背景")
    @Transient
    private String chatbackground = "";
    /**
     * 判断是不是匿名群
     * @return
     */
    public boolean isAnonymousGroup() {
    	return this.grouptype == GROUP_TYPE_ANONYMOUS;
    }
    
    public long getInfotime() {
		return infotime;
	}
	public void setInfotime(long infotime) {
		this.infotime = infotime;
	}
	
    public long getSyssetting() {
        return syssetting;
    }

    public void setSyssetting(long syssetting) {
        this.syssetting = syssetting;
    }
    
    public short getGrouptype() {
        return grouptype;
    }

    public void setGrouptype(short grouptype) {
        this.grouptype = grouptype;
    }
    
    public String getEcdhprivkey() {
        return ecdhprivkey;
    }

    public void setEcdhprivkey(String ecdhprivkey) {
        this.ecdhprivkey = ecdhprivkey;
    }

    public String getEcdhpubkey() {
        return ecdhpubkey;
    }

    public void setEcdhpubkey(String ecdhpubkey) {
        this.ecdhpubkey = ecdhpubkey;
    }
    
    public String getGroupface() {
        return groupface;
    }

    public void setGroupface(String groupface) {
        this.groupface = groupface;
    }
    
    public UserInfo getCreator() {
        return creator;
    }

    public String getGroupnotice() {
        return groupnotice;
    }

    public void setGroupnotice(String groupnotice) {
        this.groupnotice = groupnotice;
    }
    
    public void setCreator(UserInfo creator) {
        this.creator = creator;
    }
    
    public void setGroupid(int groupid) {
        this.groupid = groupid;
    }

    public int getGroupid() {
        return this.groupid;
    }

    public void setGroupname(String groupname) {
        this.groupname = groupname;
    }

    public String getGroupname() {
        return this.groupname;
    }

    public void setCreateuserid(int createuserid) {
        this.createuserid = createuserid;
    }

    public int getCreateuserid() {
        return this.createuserid;
    }

    public void setCreatetime(long createtime) {
        this.createtime = createtime;
    }

    public long getCreatetime() {
        return this.createtime;
    }

    public void setUsernum(int usernum) {
        this.usernum = usernum;
    }

    public int getUsernum() {
        return this.usernum;
    }
    
    public short getStatus() {
        return status;
    }

    public void setStatus(short status) {
        this.status = status;
    }
    
    
    public String getChatbackground() {
		return chatbackground;
	}

	public void setChatbackground(String chatbackground) {
		this.chatbackground = chatbackground;
	}

	public GroupDetailHis createTableHis(long now) {
    	GroupDetailHis his = copyer.apply(new GroupDetailHis(), this);
        his.setRemovetime(now);
        his.setSeqid(his.getGroupid() + "-" +Utility.format36time(now)); //对象id + 时间
        return his;
    }
}
